/**
 * @Author:  renyc
 * @Date: 2022年12月6日13:03:59
 */

'use strict';

import * as echarts from 'echarts';
import GLMapCoordSystem from '../viewer/coordinate/GLMapCoordSystem';

class EChartsRegistery{

    /**
     * 在ECharts上注册Cesium
     * 在使用ECharts之前，需要现在ECharts上注册Cesium。主要有2个作用
     * 1）注册坐标系统GLMapCoordSystem
     * 2）进行坐标变换
     *    调用GLMapCoordSystem.dataToPoint方法，将Cesium的地理坐标转换为Canvas的屏幕坐标。
     * @param {Viewer} viewer 
     */
    static register(viewer){
        window.viewer = viewer.delegate;
        //echarts.viewer = viewer.delegate;
        //echarts.glMap = viewer.scene;        

        echarts.extendComponentModel({
            type: 'GLMap',
            getViewer: function() {
                return window.viewer
            },
            defaultOption: {
                roam: false
            }
        });

        echarts.extendComponentView({
            type: 'GLMap',
            init: function(ecModel, api) {
                this.api = api;
                //echarts.viewer.scene.postRender.addEventListener(this.moveHandler, this);
                window.viewer.scene.postRender.addEventListener(this.moveHandler, this);
            },
            moveHandler: function(t, e) {
                this.api.dispatchAction({
                    type: 'GLMapRoam'
                })
            },
            render: function(t, e, i) {

            },
            dispose: function(t) {
                //echarts.viewer.scene.postRender.removeEventListener(this.moveHandler, this);
                window.viewer.scene.postRender.removeEventListener(this.moveHandler, this);
            }
        })


        echarts.registerCoordinateSystem('GLMap', GLMapCoordSystem)
        echarts.registerAction({
                type: 'GLMapRoam',
                event: 'GLMapRoam',
                update: 'updateLayout'
            },
            function(payload, ecModel) {

            }
        )
    }
}

export default EChartsRegistery
